Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
		Me.SuspendLayout()
		'
		'Form1
		'
		Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
		Me.ClientSize = New System.Drawing.Size(474, 394)
		Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
		Me.MaximizeBox = False
		Me.Name = "Form1"
		Me.Text = "Form1"
		Me.ResumeLayout(False)

	End Sub

#End Region

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim engine As New Alpha3D.MyDevice
        engine.SetWindowedMode(Me)

        'setup camera
        Dim camera As New Alpha3D.Camera(engine)
        With camera
            .Reset(True)
            .Position = New Vector3(0, 100, -300)
            .LookAt = New Vector3(0, 100, 0)
            .Orientation = New Vector3(0, 1, 0)
            .FieldOfView = Direct3D.Geometry.DegreeToRadian(90)
            .AspectRatio = Me.Width / Me.Height
            .NearPlane = 1.0
            .FarPlane = 1000
            .UpdateVP()
        End With
        'end camera

        Dim trikotnik(2) As Direct3D.CustomVertex.PositionColoredTextured
        For i As Integer = 0 To 2
            trikotnik(i) = New Direct3D.CustomVertex.PositionColoredTextured
        Next

        Dim scn As New Alpha3D.Scene
        scn.Render()

        With trikotnik(0)
            .X = 0
            .Y = 100
            .Z = 0
            .Tu = 0
            .Tv = 0
            .Color = Color.White.ToArgb
        End With
        With trikotnik(1)
            .X = 100
            .Y = 100
            .Z = 0
            .Tu = 1
            .Tv = 0
            .Color = Color.White.ToArgb
        End With
        With trikotnik(2)
            .X = 100
            .Y = 0
            .Z = 0
            .Tu = 1
            .Tv = 1
            .Color = Color.White.ToArgb
        End With

        engine.Device.VertexFormat = Direct3D.CustomVertex.PositionColoredTextured.Format
        engine.Device.RenderState.Lighting = False
        Application.DoEvents()

        Dim tex As Direct3D.Texture
        tex = Direct3D.Texture.FromBitmap(engine.Device, New Bitmap("texture.bmp"), Direct3D.Usage.None, Direct3D.Pool.Managed)
        engine.SetTexture(0, tex)

        'megla
        engine.Fog(True, Color.CornflowerBlue, Direct3D.FogMode.Linear, 0.6, 0, 500)

        Me.Show()
        Application.DoEvents()

        Dim angle As Single = 0.002

        Do While Me.Created
            engine.BeginScene(Color.CornflowerBlue)

            'angle += 0.0000002
            engine.Device.Transform.World = Matrix.Multiply(Matrix.RotationY(angle), engine.Device.Transform.World)
            engine.Device.DrawUserPrimitives(Direct3D.PrimitiveType.TriangleList, 1, trikotnik)

            engine.EndScene(True)
            Application.DoEvents()
        Loop

    End Sub

    Private Sub Form1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Click
        Me.Dispose()
        End
    End Sub
End Class
